package com.sjgs.gis.domain;

import com.sjgs.gis.domain.enumeration.NodeStatus;
import lombok.*;

import java.io.Serializable;
import java.net.InetSocketAddress;

@NoArgsConstructor
@Getter
@Setter
@ToString
@EqualsAndHashCode
@Data
public class Node implements Serializable {
    private static final long serialVersionUID = 1L;
    String instanceId;
    String serviceId;
    String host;
    Integer port;
    Integer grpcport;
    NodeStatus status = NodeStatus.O;

    public Node(String instanceId, String serviceId, String host, Integer port) {
        this.instanceId = instanceId;
        this.serviceId = serviceId;
        this.host = host;
        this.port = port;
        this.grpcport = port + 1;
    }

    public Node(String instanceId, String serviceId, String host, Integer port, Integer grpcport) {
        this.instanceId = instanceId;
        this.serviceId = serviceId;
        this.host = host;
        this.port = port;
        this.grpcport = grpcport;
    }

    public String getInstanceId() {
        return instanceId;
    }

    public void setInstanceId(String instanceId) {
        this.instanceId = instanceId;
    }

    public String getServiceId() {
        return serviceId;
    }

    public void setServiceId(String serviceId) {
        this.serviceId = serviceId;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public Integer getGrpcport() {
        return grpcport;
    }

    public void setGrpcport(Integer grpcport) {
        this.grpcport = grpcport;
    }

    public InetSocketAddress getSocketAddress() {
        return new InetSocketAddress(host, port);
    }

    public NodeStatus getStatus() {
        return status;
    }

    public void setStatus(NodeStatus status) {
        this.status = status;
    }
}
